from django.contrib import admin

# Register your models here.
from .models import *

class PermissionConfig(admin.ModelAdmin):
    """
    权限
    """
    list_display = ['id', 'permission_name', 'url',]
    list_editable = ['url']

    # ordering = ['id']


class RoleConfig(admin.ModelAdmin):
    """
    角色
    """
    list_display = ['id', 'role_name', '权限']
    # list_editable = ['role_name']
    # ordering = ['id']
    def 权限(self, obj):
        return [a.permission_name for a in obj.permissions.all()]



class UserInfoConfig(admin.ModelAdmin):
    """
    用户
    """
    # inlines = [RoleInLine, ]
    def 角色(self, obj):
        return [a.role_name for a in obj.roles.all()]
    list_display = ['id', 'name', 'password', '角色']
    # ordering = ['id']
    list_editable = ['name', 'password']


class MenuConfig(admin.ModelAdmin):
    """
    用户
    """
    list_display = ['id', 'title', 'parent']
    list_editable = ['parent']

admin.site.register(Permission, PermissionConfig)
admin.site.register(Role, RoleConfig)
admin.site.register(UserInfo, UserInfoConfig)
admin.site.register(Menu, MenuConfig)